<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Controller.php 2010-09-07 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Like_Widget_BoxController extends Engine_Content_Widget_Abstract
{
	protected $_childCount;
	
  public function indexAction()
  {
  	if (!Engine_Api::_()->getDbTable('modules', 'core')->isModuleEnabled('like')){
  		$this->setNoRender();
  		return ;
  	}
  	
    if (!Engine_Api::_()->getApi('settings', 'core')->getSetting('like.profile.enabled', 1)){
      $this->setNoRender();
      return ;
    }
    
  	$this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
  	
  	if ($subject->getType() == 'user'){
      if (!Engine_Api::_()->authorization()->isAllowed('like', $subject, 'create')){
        $this->setNoRender();
        return ;
      }
  	}
  	
 		if (!Engine_Api::_()->like()->isEnabledLikeClub($subject)){
 			$this->setNoRender();
 			return ;
 		}

    $settings = Engine_Api::_()->getApi('settings', 'core');
    $ipp = $settings->getSetting('like.likes_count', 9);

 		$this->view->likes = $likes = Engine_Api::_()->like()->getLikes($subject);
    $likes->setItemCountPerPage($ipp);
 		
 		if (!$likes || $likes->getTotalItemCount() == 0){
 			$this->setNoRender();
 			return ;
 		}
 		
    if( $this->_getParam('titleCount', false) && $likes->getTotalItemCount() > 0 ) {
      $this->_childCount = $likes->getTotalItemCount();
    }
  }
  
  public function getChildCount()
  {
    return $this->_childCount;
  }
}